package com.bear.newsset.dao.entity;

import com.bear.newsset.dao.DaoSession;
import com.bear.newsset.dao.NewsDataSqlEntityDao;
import com.bear.newsset.dao.QueryNewsDataEntityDao;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.JoinProperty;
import org.greenrobot.greendao.annotation.OrderBy;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.annotation.Unique;

import java.util.List;

/**
 * 查询新闻数据的实体类
 */
@Entity
public class QueryNewsDataEntity {
    @Id
    @Unique
    private Long queryId;
    @Unique
    private Long mainLableId;          //主标签Id
    private Long childLableId;         //子标签Id，因为子标签默认为0，所以不能设为唯一id
    @ToMany(joinProperties = {@JoinProperty(name = "queryId", referencedName = "queryId")})
    @OrderBy("publishDate DESC")
    private List<NewsDataSqlEntity> data;     //新闻数据

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 2137087323)
    private transient QueryNewsDataEntityDao myDao;
    @Generated(hash = 1691179752)
    public QueryNewsDataEntity(Long queryId, Long mainLableId, Long childLableId) {
        this.queryId = queryId;
        this.mainLableId = mainLableId;
        this.childLableId = childLableId;
    }
    @Generated(hash = 1886891548)
    public QueryNewsDataEntity() {
    }
    public Long getQueryId() {
        return this.queryId;
    }
    public void setQueryId(Long queryId) {
        this.queryId = queryId;
    }
    public Long getMainLableId() {
        return this.mainLableId;
    }
    public void setMainLableId(Long mainLableId) {
        this.mainLableId = mainLableId;
    }
    public Long getChildLableId() {
        return this.childLableId;
    }
    public void setChildLableId(Long childLableId) {
        this.childLableId = childLableId;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 291045910)
    public List<NewsDataSqlEntity> getData() {
        if (data == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            NewsDataSqlEntityDao targetDao = daoSession.getNewsDataSqlEntityDao();
            List<NewsDataSqlEntity> dataNew = targetDao
                    ._queryQueryNewsDataEntity_Data(queryId);
            synchronized (this) {
                if (data == null) {
                    data = dataNew;
                }
            }
        }
        return data;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1283600904)
    public synchronized void resetData() {
        data = null;
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 68738953)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getQueryNewsDataEntityDao() : null;
    }
}
